package com.example.makerspace.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.makerspace.domain.CategoryDO;
import com.example.makerspace.dto.CategoryDTO;
import com.example.makerspace.mapper.CategoryMapper;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Component
public class CategoryDAO extends BaseDAO<CategoryDO>{
    public final static String TYPE = "type";
    public final static String CATEGORYNAME  = "category_name";
    @Resource
    private CategoryMapper categoryMapper;

    @PostConstruct
    public void init(){
        this.mapper = categoryMapper;
    }

    public CategoryDO selectByTypeAndName(CategoryDTO categoryDTO) {
        return categoryMapper.selectOne(new QueryWrapper<CategoryDO>()
                .eq(TYPE, categoryDTO.getType())
                .eq(CATEGORYNAME, categoryDTO.getCategoryName()));
    }

    public List<CategoryDO> list(Map<String, String> params) {
        return categoryMapper.selectList(new QueryWrapper<CategoryDO>()
                .eq(TYPE, MapUtils.getString(params, TYPE)));
    }
}
